package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketStorage;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author Austin Hsu
 * @Date 2022/9/8 16:07
 */

@RestController
@RequestMapping("admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    @RequestMapping("list")
    public BaseRespVo list(MarketStorage marketStorage, BasePageInfo info) {           //分页 浏览器得到1.数据 2.分页参数
        CommonData<MarketStorage> data = storageService.query(marketStorage, info);
        return BaseRespVo.ok2(data);
    }

    @RequestMapping("delete")
    public BaseRespVo list(@RequestBody MarketStorage marketStorage) {
        storageService.delete(marketStorage.getId());
        return BaseRespVo.ok3();
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketStorage marketStorage) {
storageService.update(marketStorage);
        return BaseRespVo.ok3();
    }

    @RequestMapping("create")              //1.上传文件到路径 得到文件名  2.insert插入数据库  3.select返回这条数据
    public BaseRespVo create(MultipartFile file) throws IOException {
        MarketStorage data=storageService.create(file);
        return BaseRespVo.ok2(data);
    }

}
